/*
 * File: exercise8.cpp
 * -------------------
 * This program Reverse the digits in an integer.
 * compile command :
 * g++ -Wall -g exercise8.cpp -o exercise8 -lStanfordCPPLib -I ../include/
 */

#include <iostream>
#include "simpio.h"
using namespace std;
int digitreverse(int orginal);

int main()
{
	int i ;
	cout<<"This program reverse the digits in an integer."<<endl;
	while((i = getInteger("Enter a positive integer: ")) < 0)
	{
		cout<<"negative integer!"<<endl;
	}
	int output = digitreverse(i);
	cout<<"The reversed integer is "<<output<<endl;
	return 0;
}

int digitreverse(int orginal)
{
	int output = 0;
	while(orginal > 0)
	{
		output = 10 * output + orginal % 10; 
		orginal /= 10;
	}
	return output;
}
